<template lang="">
    <div>
      <div class="loading-img">
        <img src="@/assets/homePicture/loading.png"/>
      </div>
    </div>
</template>
<script>
export default {
  data() {
    return {};
  },
  mounted() {
    let that = this;
    let corpId = "";
    localStorage.clear();
    dd.ready(function() {
      // ding66011e364a5ee19c35c2f4657eb6378f
      // dd.ready参数为回调函数，在环境准备就绪时触发，jsapi的调用需要保证在该回调函数触发后调用，否则无效。
      that.$get("get_crop_id").then(res => {
        if (res.success) {
          corpId = res.data.corpId;
          dd.runtime.permission.requestAuthCode({
            corpId: corpId,
            onSuccess: function(result) {
              console.log(result.code);
              let params = {
                code: result.code
              };
              that.$get("login", params).then(res => {
                console.log("登陆成功");
                that.$get("getUserInfo").then(res => {
                  if (res.success) {
                    let roleList = JSON.stringify(res.data.role);
                    localStorage.setItem("role", roleList);
                    that.loadingImg = false;
                    console.log("权限获取成功");
                    console.warn('执行步骤一')
                    that.$router.push({
                      path: "/Home"
                    });
                  } else {
                    Toast({
                      message: "获取权限失败，请刷新重试",
                      position: "center",
                      duration: 3000
                    });
                  }
                });
              });
              /*{
                  code: 'hYLK98jkf0m' //string authCode
              }*/
            },
            onFail: function(err) {}
          });
        }
      });
    });
    that.$get("getUserInfo").then(res => {
      if (res.success) {
        let roleList = JSON.stringify(res.data.role);
        localStorage.setItem("role", roleList);
        console.warn('执行步骤一')
        that.$router.push({
          path: "/Home"
        });
      }
    });
  },
};
</script>
<style lang="less" scoped>
.loading-img {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  // background: url("~@/assets/homePicture/loading.png") 0 0 no-repeat;
  background-size: 100%;
  z-index: 999;
}
img{
  width: 100%;
  height: 100%;
}
</style>